﻿


$(document).ready(function () {
    lblKeyid.SetText($.query.get('Keyid'));
    txtUsername.SetText($.query.get('UserName'));
    txtRealname.SetText($.query.get('RealName'));
    //删除按钮不可用
    doSetEnableMenuItems('btnDelete', false);
});


//新增岗位
var doAdd = function () {
    var url = '../../../Views/Permission/Popup/AddUserRole.aspx?Keyid=' + lblKeyid.GetText();
    url += '&UserName=' + txtUsername.GetText();
    Shadowbox.open({
        content: url,
        player: 'iframe',
        title: '新增岗位',
        height: 600,
        width: 900
    });
}
var doDelete = function () {
    $.messager.confirm('确认提示', '确认删除吗?', function (result) {
        if (result) {
            gvwList.GetSelectedFieldValues('Keyid', function (result) {
                var roleKeyids = [];
                for (var i = 0; i < result.length; i++) {
                    roleKeyids.push(result[i]);
                }
                SGDemo.Permission.AssociatedRoles.BulkDelete(lblKeyid.GetText(), roleKeyids, function (result) {
                    if (result.value) {
                        $.messager.show({
                            title: '信息提示',
                            msg: '删除岗位成功！'
                        });
                        //本页面GridView刷新
                        gvwList.PerformCallback();
                        //删除按钮不可用
                        doSetEnableMenuItems('btnDelete', false);
                    } else {
                        $.messager.show({
                            title: '信息提示',
                            msg: '删除岗位失败！'
                        });
                    }
                });
            });
        }
    });
}

var doRefresh = function () {
    gvwList.PerformCallback();
}
/****************************/
//启用或者全部菜单按钮
var doSetEnableMenuItems = function (menuItemName, isEnable) {
    menuHeader.GetItemByName(menuItemName).SetEnabled(isEnable);
}

//GridView选中全部或者取消选中全部
var doSelectOrUnselectAll = function (s, e) {
    gvwList.SelectAllRowsOnPage(s.GetChecked());
}

//GridView选择事件
function doSelectionChanged() {
    var selectedCount = this.gvwList.GetSelectedRowCount();
    if (selectedCount == 0) {//没有选中，
        doSetEnableMenuItems('btnDelete', false);
    } else if (selectedCount >= 1) {//选中多条
        doSetEnableMenuItems('btnDelete', true);
    }
}